#include<bits/stdc++.h>
using namespace std;

class Solution {
public:
    int zero, cnt, n, ans;
    int build[21];
    void dfs(vector<vector<int>>& requests, int pos){
        if(pos == requests.size()){
            if(zero == n){
                ans = max(ans, cnt);
            }
            return;
        }
        dfs(requests, pos + 1);

        int temp = zero;
        ++cnt;
        if(!build[requests[pos][0]])zero--;
        build[requests[pos][0]]--;
        if(!build[requests[pos][0]])zero++;

        if(!build[requests[pos][1]])zero--;
        build[requests[pos][1]]++;
        if(!build[requests[pos][1]])zero++;

        dfs(requests, pos + 1);
        --build[requests[pos][1]];
        ++build[requests[pos][0]];
        --cnt;
        zero = temp;
    }

    int maximumRequests(int n, vector<vector<int>>& requests) {
        this->n = n;
        zero = n;
        ans = 0;
        cnt = 0;
        memset(build, 0, sizeof(build));
        dfs(requests, 0);
        return ans;
    }
};
/**
 * @brief 2022.2.28
 * 
 */